package net.study;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloServlet
 */
public class HelloServlet extends HttpServlet {

	public static void main(String[] args) {
		System.out.println(getLang());
	}

	public static String getLang() {
		return System.getProperty("user.language");
	}

	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		response.setContentType("text/html");
//		PrintWriter writer = response.getWriter();
//		writer.println("<h1>get</h1>");
		service(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		response.setContentType("text/html");
//		PrintWriter writer = response.getWriter();
//		writer.println("<h1>post</h1>");
		service(request,response);
	}

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml");
		PrintWriter writer = response.getWriter();
		writer.println("<html>");
		writer.println("<h1>service</h1>");
		writer.println("request.getMethod():"+request.getMethod());
		writer.println("<br/>");
		writer.println("request.getRequestURI():"+request.getRequestURI());
		writer.println("<br/>");
		writer.println("request.getRequestURL():"+request.getRequestURL());
		writer.println("</html>");
	}
}
